package newsletterApi

import (
	"github.com/Sir-yuChen/funAnalyse/model/common/response"
	"github.com/Sir-yuChen/funAnalyse/model/request"
	"github.com/Sir-yuChen/funAnalyse/utils"
	"github.com/gin-gonic/gin"
)

type CommunicationController struct{}

// GetCommunicationBasis 获取用户通讯录&聊天室信息
// @Summary 获取用户通讯录
// @Tags 站内信
// @Accept application/json
// @Produce application/json
// @response 200 {object} response.Response  "接口返回信息"
// @Router /funAnalyse/newsletter/getCommunicationBasis [GET]
func (b *CommunicationController) GetCommunicationBasis(c *gin.Context) {
	apiReturn := communicationService.GetCommunicationBasis(c)
	response.WithApiReturn(apiReturn, c)
	return
}

// AddCommunicationFriend 添加好友请求
// @Summary 添加好友请求
// @Tags 站内信
// @Accept application/json
// @Produce application/json
// @Param data body request.AddCommunicationFriendRequest true "请求参数"
// @response 200 {object} response.Response  "接口返回信息"
// @Router /funAnalyse/newsletter/addCommunicationFriend [GET]
func (b *CommunicationController) AddCommunicationFriend(c *gin.Context) {
	var req request.AddCommunicationFriendRequest
	if err := c.ShouldBindJSON(&req); err != nil {
		utils.ErrValidatorResp(err, "AddCommunicationFriend", req, c)
		return
	}
	apiReturn := communicationService.AddCommunicationFriend(c, &req)
	response.WithApiReturn(apiReturn, c)
	return
}

// AddFriend 添加好友
// @Summary 添加好友
// @Tags 站内信
// @Accept application/json
// @Produce application/json
// @Param data body request.AddCommunicationFriendRequest true "请求参数"
// @response 200 {object} response.Response  "接口返回信息"
// @Router /funAnalyse/newsletter/addFriend [GET]
func (b *CommunicationController) AddFriend(c *gin.Context) {
	var req request.AddFriendRequest
	if err := c.ShouldBindJSON(&req); err != nil {
		utils.ErrValidatorResp(err, "AddFriend", req, c)
		return
	}
	apiReturn := communicationService.AddFriend(c, &req)
	response.WithApiReturn(apiReturn, c)
	return
}

// CreateChatroom 创建聊天室
// @Summary 创建websocket
// @Tags 站内信
// @Accept application/json
// @Produce application/json
// @Param data body request.CreateChatroomRequest true "请求参数"
// @response 200 {object} response.Response  "接口返回信息"
// @Router /funAnalyse/newsletter/createChatroom [GET]
func (b *CommunicationController) CreateChatroom(c *gin.Context) {
	var req request.CreateChatroomRequest
	if err := c.ShouldBindJSON(&req); err != nil {
		utils.ErrValidatorResp(err, "CreateChatroom", req, c)
		return
	}
	apiReturn := communicationService.CreateChatroom(c, &req)
	response.WithApiReturn(apiReturn, c)
	return
}

// CreateWebsocket 创建长连接
// @Summary 创建websocket
// @Tags 站内信
// @Accept application/json
// @Produce application/json
// @Param data body request.CreateChatroomRequest true "请求参数"
// @response 200 {object} response.Response  "接口返回信息"
// @Router /funAnalyse/newsletter/createWebsocket [GET]
func (b *CommunicationController) CreateWebsocket(c *gin.Context) {
	apiReturn := communicationService.CreateWebsocket(c)
	response.WithApiReturn(apiReturn, c)
	return
}

// SendCommunicationMsg 发送消息
// @Summary 发送消息
// @Tags 站内信
// @Accept application/json
// @Produce application/json
// @Param data body request.SendMessageRequest true "请求参数"
// @response 200 {object} response.Response  "接口返回信息"
// @Router /funAnalyse/newsletter/sendCommunicationMsg [GET]
func (b *CommunicationController) SendCommunicationMsg(c *gin.Context) {
	var req request.SendMessageRequest
	if err := c.ShouldBind(&req); err != nil {
		utils.ErrValidatorResp(err, "SendCommunicationMsg", req, c)
		return
	}
	apiReturn := communicationService.SendCommunicationMsg(c, &req)
	response.WithApiReturn(apiReturn, c)
	return
}

// ReadChatroomMsg 读取聊天室消息
// @Summary 读取消息列表
// @Tags 站内信
// @Accept application/json
// @Produce application/json
// @Param data body request.ReadMessageRequest true "请求参数"
// @response 200 {object} response.Response  "接口返回信息"
// @Router /funAnalyse/newsletter/readChatroomMsg [GET]
func (b *CommunicationController) ReadChatroomMsg(c *gin.Context) {
	var req request.ReadMessageRequest
	if err := c.ShouldBind(&req); err != nil {
		utils.ErrValidatorResp(err, "ReadChatroomMsg", req, c)
		return
	}
	apiReturn := communicationService.ReadChatroomMsg(&req, c)
	response.WithApiReturn(apiReturn, c)
	return
}

// UpdateFriendInfo 修改好友信息
// @Summary 修改好友信息
// @Tags 站内信
// @Accept application/json
// @Produce application/json
// @Param data body request.UpdateFriendInfoRequest true "请求参数"
// @response 200 {object} response.Response  "接口返回信息"
// @Router /funAnalyse/newsletter/updateFriendInfo [POST]
func (b *CommunicationController) UpdateFriendInfo(c *gin.Context) {
	var req request.UpdateFriendInfoRequest
	if err := c.ShouldBindJSON(&req); err != nil {
		utils.ErrValidatorResp(err, "UpdateFriendInfo", req, c)
		return
	}
	apiReturn := communicationService.UpdateFriendInfo(&req, c)
	response.WithApiReturn(apiReturn, c)
	return
}

// UpdateBasisRoomInfo 修改聊天室信息
// @Summary 修改聊天室信息
// @Tags 站内信
// @Accept application/json
// @Produce application/json
// @Param data body request.UpdateBasisRoomInfoRequest true "请求参数"
// @response 200 {object} response.Response  "接口返回信息"
// @Router /funAnalyse/newsletter/updateBasisRoomInfo [POST]
func (b *CommunicationController) UpdateBasisRoomInfo(c *gin.Context) {
	var req request.UpdateBasisRoomInfoRequest
	if err := c.ShouldBindJSON(&req); err != nil {
		utils.ErrValidatorResp(err, "UpdateBasisRoomInfo", req, c)
		return
	}
	apiReturn := communicationService.UpdateBasisRoomInfo(&req, c)
	response.WithApiReturn(apiReturn, c)
	return
}
